package com.sghd.candy.module.box.facade;

import com.sghd.candy.module.box.service.PlayerBoxService;
import com.sghd.candy.module.player.manager.Player;
import com.sghd.candy.module.player.service.PlayerService;
import com.sghd.common.console.ConsoleBean;
import com.sghd.pojo.candy.box.enums.KeyType;
import com.sghd.pojo.candy.box.vo.BoxKeyVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Allen
 * @date 2018/12/25
 */
@ConsoleBean
@Component
public class BoxFacadeImpl implements BoxFacade {
    private static final Logger logger = LoggerFactory.getLogger(BoxFacadeImpl.class);
    @Autowired
    private PlayerService playerService;
    @Autowired
    private PlayerBoxService playerBoxService;

    @Override
    public List<Map> openBox(long playerId, KeyType keyType, Integer openCount) {
        Player player = playerService.load(playerId);
        if (player == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("玩家ID[{}]，不存在！", playerId);
            }
            return null;
        }

        return playerBoxService.openBox(player, keyType, openCount);
    }

    @Override
    public List<Map> openBox(long playerId, KeyType keyType) {
        Player player = playerService.load(playerId);
        if (player == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("玩家ID[{}]，不存在！", playerId);
            }
            return null;
        }

        return playerBoxService.openBoxByTeach(player, keyType);
    }

    @Override
    public BoxKeyVo boxKeyList(long playerId) {
        return playerBoxService.getBoxKeyList(playerService.load(playerId));
    }
}
